<template>
  <l-select-panel
    ref="selectPanel"
    valueKey="f_Id"
    :multiple="multiple"
    :columns="columns"
    :loadSelectTable="loadTableData"
    isSaveSelectData
    @rowClick="rowClick"
  >
    <template v-slot:f_Id="scope" v-if="!multiple">
      &nbsp;&nbsp;<el-radio
        :label="scope.row.f_Id"
        size="mini"
        v-model="selectId"
        @input="choose(scope.row)"
        >&nbsp;</el-radio
      >
    </template>
  </l-select-panel>
</template>
<script>
const api = window.$api.erpcase.material;
const apiSupplier = window.$api.erpcase.supplier;
export default {
  name: "l-choose-material",
  props: {
    multiple: {
      default: true,
      type: Boolean,
    },
    supplierId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      columns: [
        { label: "物料编号", prop: "f_Number", minWidth: 120 },
        { label: "物料名称", prop: "f_Name", minWidth: 120 },
        {
          label: "规格型号",
          prop: "f_Model",
          minWidth: 120,
          align: "left",
        },
        {
          label: "单位",
          prop: "f_Unit",
          minWidth: 80,
          align: "center",
          dataType: "dataSource",
          dataCode: "ERP_Unit",
          valueKey: "f_id",
          labelKey: "f_name",
        },
      ],
      selectId: "",
    };
  },
  mounted() {
    this.init();
    if (!this.multiple) {
      let list = { label: "操作", prop: "f_Id", width: 64, align: "center" };
      this.columns.push(list);
    }
  },
  methods: {
    init() {
      this.$refs.selectPanel.init();
    },
    async loadTableData(queryData) {
      let data;
      if (this.supplierId) {
        queryData.f_SupplierId = this.supplierId;
        data = await this.$awaitWraper(apiSupplier.supplymaterialpage(queryData));
      } else {
        queryData.sidx = "f_Number";
        data = await this.$awaitWraper(api.getPage(queryData));
      }
      return data;
    },
    async getSelectData() {
      let select =  await this.$refs.selectPanel.getSelected(); 
      console.log(select,'select');
      return select;
    },
    resetForm() {
      this.$refs.selectPanel.reset();
      this.$refs.selectPanel.init();
    },
    rowClick(row) {
      if (!this.multiple) {
        this.$emit("rowClick", row);
      }
    },
    // 选择
    choose(row) {
      this.f_Id = row.f_Id;
    },
  },
};
</script>